package com.fastdfs.controller.controllerutils;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ControllerAdvice
public class MyGlobalExceptionHandler {
    @ModelAttribute(name = "md")
    public Map<String,Object> mapData() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("http", "http://localhost:20210");
        return map;
    }
    @ModelAttribute(name = "li")
    public List<String> listData() {
        List<String>  list = new ArrayList<>();
        list.add("http://localhost:20210");
        list.add("http://localhost:11111");
        return list;
    }

/**
 * 定义完成后，在任何一个Controller 的接口中，都可以获取到这里定义的数据：
 * 使用方法:
 *     @GetMapping("/hello")
 *     public void hello(Model model) {
 *
    Map<String, Object> stringObjectMap = model.asMap(); //获取全局配置的 变量

    获取到的数据 {md={http=http://localhost:20210}, li=[http://localhost:20210, http://localhost:11111]}

    Map<String,String> ma= (Map<String, String>) stringObjectMap.get("md");
    String http =(String) ma.get("http");
    System.out.println(http); //http://localhost:20210

    List<String> list= (List<String>) stringObjectMap.get("li");
    System.out.println(list.get(0)); //http://localhost:20210
 *
 *     }
 *
 *
 */



}